# 获取按键信号 点亮灯泡
import RPi.GPIO as GP
import time

def control_01():
    GP.setmode(GP.BOARD)
    GP.setup(15,GP.IN)
    # GP.setup(15,GP.IN, pull_up_down=GP.PUD_DOWN)
    # GP.setup(15,GP.IN, pull_up_down=GP.PUD_UP)
    GP.setup((11,12),GP.OUT)
    GP.output(11,0)  # red
    GP.output(12,0)  # green
    while True:
        # button 按下:输入0 抬起:输入1
        # print(GP.input(15))
        if GP.input(15): # 抬起 red
            GP.output(12,0)
            GP.output(11,1)
        else: #  按下 green
            GP.output(11,0)
            GP.output(12,1)
        # time.sleep(1)

def control_02():
    GP.setmode(GP.BOARD)
    GP.setup(15,GP.IN, pull_up_down=GP.PUD_DOWN)
    GP.setup(15,GP.IN, pull_up_down=GP.PUD_UP)  # 加上拉电阻, 目的是去除干扰
    GP.setup(11,GP.OUT)
    GP.output(11,0)
    count =0
    while True:
        result = GP.input(15)
        if result:
            count+=1
            print(f'count:{count}')
            time.sleep(0.05)

    
def close():
    GP.cleanup()


if __name__=='__main__':
    print(GP.BOTH)
    print(GP.RISING)
    try:
        control_02()
    except:
        close()

